<template>
    <div class="wrapper">
      <!-- 在swiper标签里面添加 v-if='swiperList.length' 表示的是，第一次加载的时候，因为数组是空的，所以，swipper不会被创建，等有数据的时候才会被创建，这样就可以解决直接显示第四页的问题了 。这种方法的处理不够优雅，所以我们准备在computed属性来解决 -->
        <swiper :options="swiperOption" v-if='showSwiper'>
            <!-- slides -->
            <swiper-slide v-for="item of swiperList" :key="item.id">
                <img class="swiper-img" :src="item.imgUrl" />
            </swiper-slide>
            <!-- Optional controls -->
            <div class="swiper-pagination" slot="pagination"></div>
            <!-- <div class="swiper-button-prev" slot="button-prev"></div>
            <div class="swiper-button-next" slot="button-next"></div> -->
            <!-- <div class="swiper-scrollbar"   slot="scrollbar"></div> -->
        </swiper>
    </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    swiperList: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true/* 支持循环轮播 */
      }
    }
  },
  computed: {
    showSwiper () {
      return this.swiperList.length
    }
  }
}
</script>

<style lang="stylus" scoped>
.wrapper
  overflow hidden
  width 100%
  height 0
  padding-bottom:54.48%
  background #cccccc
.swiper-img
    width 100%
.wrapper >>> .swiper-pagination-bullet-active
    background #ffffff
</style>
